import { OrdersGoodss } from './ordersGoods';
let _OrdersGoodss = OrdersGoodss;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import OrdersGoodsMock from './mallm/orders/ordersGoodsMock';
 * OrdersGoodsMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mallm/orders/ordersGoods/listKey').reply(config => {
      let params = config.params;
      let mockOrdersGoodss = _OrdersGoodss.filter(ordersGoods => {
      	if(params.id||params.id==''){ if( ordersGoods.id.indexOf(params.id)>=0) return true;}
      	if(params.orderId||params.orderId==''){ if( ordersGoods.orderId.indexOf(params.orderId)>=0) return true;}
      	if(params.goodsId||params.goodsId==''){ if( ordersGoods.goodsId.indexOf(params.goodsId)>=0) return true;}
      	if(params.goodsName||params.goodsName==''){ if( ordersGoods.goodsName.indexOf(params.goodsName)>=0) return true;}
      	if(params.goodsSn||params.goodsSn==''){ if( ordersGoods.goodsSn.indexOf(params.goodsSn)>=0) return true;}
      	if(params.productId||params.productId==''){ if( ordersGoods.productId.indexOf(params.productId)>=0) return true;}
      	if(params.numbers||params.numbers==''){ if( ordersGoods.numbers.indexOf(params.numbers)>=0) return true;}
      	if(params.marketPrice||params.marketPrice==''){ if( ordersGoods.marketPrice.indexOf(params.marketPrice)>=0) return true;}
      	if(params.retailPrice||params.retailPrice==''){ if( ordersGoods.retailPrice.indexOf(params.retailPrice)>=0) return true;}
      	if(params.isReal||params.isReal==''){ if( ordersGoods.isReal.indexOf(params.isReal)>=0) return true;}
      	if(params.goodsSpecifitionIds||params.goodsSpecifitionIds==''){ if( ordersGoods.goodsSpecifitionIds.indexOf(params.goodsSpecifitionIds)>=0) return true;}
      	if(params.listPicUrl||params.listPicUrl==''){ if( ordersGoods.listPicUrl.indexOf(params.listPicUrl)>=0) return true;}
      	if(params.goodsSpecifitionNameValue||params.goodsSpecifitionNameValue==''){ if( ordersGoods.goodsSpecifitionNameValue.indexOf(params.goodsSpecifitionNameValue)>=0) return true;}
      	if(params.deptid||params.deptid==''){ if( ordersGoods.deptid.indexOf(params.deptid)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockOrdersGoodss
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mallm/orders/ordersGoods/list').reply(config => {
      let params = config.params;
      let mockOrdersGoodss = _OrdersGoodss.filter(ordersGoods => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(ordersGoods.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderId||params.orderId==''){if(ordersGoods.orderId.indexOf(params.orderId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.goodsId||params.goodsId==''){if(ordersGoods.goodsId.indexOf(params.goodsId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.goodsName||params.goodsName==''){if(ordersGoods.goodsName.indexOf(params.goodsName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.goodsSn||params.goodsSn==''){if(ordersGoods.goodsSn.indexOf(params.goodsSn)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.productId||params.productId==''){if(ordersGoods.productId.indexOf(params.productId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.numbers||params.numbers==''){if(ordersGoods.numbers.indexOf(params.numbers)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.marketPrice||params.marketPrice==''){if(ordersGoods.marketPrice.indexOf(params.marketPrice)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.retailPrice||params.retailPrice==''){if(ordersGoods.retailPrice.indexOf(params.retailPrice)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isReal||params.isReal==''){if(ordersGoods.isReal.indexOf(params.isReal)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.goodsSpecifitionIds||params.goodsSpecifitionIds==''){if(ordersGoods.goodsSpecifitionIds.indexOf(params.goodsSpecifitionIds)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.listPicUrl||params.listPicUrl==''){if(ordersGoods.listPicUrl.indexOf(params.listPicUrl)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.goodsSpecifitionNameValue||params.goodsSpecifitionNameValue==''){if(ordersGoods.goodsSpecifitionNameValue.indexOf(params.goodsSpecifitionNameValue)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.deptid||params.deptid==''){if(ordersGoods.deptid.indexOf(params.deptid)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockOrdersGoodss
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockOrdersGoodss.length;
      mockOrdersGoodss = mockOrdersGoodss.filter((ordersGoods, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockOrdersGoodss,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mallm/orders/ordersGoods/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _OrdersGoodss = _OrdersGoodss.filter(ordersGoods => ordersGoods.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mallm/orders/ordersGoods/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _OrdersGoodss = _OrdersGoodss.filter(ordersGoods => !params.includes(ordersGoods.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mallm/orders/ordersGoods/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,orderId,goodsId,goodsName,goodsSn,productId,numbers,marketPrice,retailPrice,isReal,goodsSpecifitionIds,listPicUrl,goodsSpecifitionNameValue,deptid } = params;
      _OrdersGoodss.some(ordersGoods => {
        if (ordersGoods.id === id) {
			ordersGoods.id = id;
			ordersGoods.orderId = orderId;
			ordersGoods.goodsId = goodsId;
			ordersGoods.goodsName = goodsName;
			ordersGoods.goodsSn = goodsSn;
			ordersGoods.productId = productId;
			ordersGoods.numbers = numbers;
			ordersGoods.marketPrice = marketPrice;
			ordersGoods.retailPrice = retailPrice;
			ordersGoods.isReal = isReal;
			ordersGoods.goodsSpecifitionIds = goodsSpecifitionIds;
			ordersGoods.listPicUrl = listPicUrl;
			ordersGoods.goodsSpecifitionNameValue = goodsSpecifitionNameValue;
			ordersGoods.deptid = deptid
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mallm/orders/ordersGoods/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,orderId,goodsId,goodsName,goodsSn,productId,numbers,marketPrice,retailPrice,isReal,goodsSpecifitionIds,listPicUrl,goodsSpecifitionNameValue,deptid } = params;
      _OrdersGoodss.push({
		id:id,
		orderId:orderId,
		goodsId:goodsId,
		goodsName:goodsName,
		goodsSn:goodsSn,
		productId:productId,
		numbers:numbers,
		marketPrice:marketPrice,
		retailPrice:retailPrice,
		isReal:isReal,
		goodsSpecifitionIds:goodsSpecifitionIds,
		listPicUrl:listPicUrl,
		goodsSpecifitionNameValue:goodsSpecifitionNameValue,
		deptid:deptid
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};